import 'package:flutter/material.dart';
import 'package:yp/config/index.dart';
import 'package:yp/helper.dart';

class TurntableAwardChanceView extends StatelessWidget {
  TurntableAwardChanceView({Key key, this.data, this.actionEvent})
      : super(key: key);
  final Map data;
  final Function(int index) actionEvent;
  @override
  Widget build(BuildContext context) {
    int integral = data == null ? 0 : data['integral_exchange_remain'] ?? 0;
    int share = data == null ? 0 : data['share_exchange_remain'] ?? 0;
    int purchase = data == null ? 0 : data['purchase_exchange_remain'] ?? 0;

    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.symmetric(horizontal: setWidth(30)),
            padding: EdgeInsets.symmetric(
                horizontal: setWidth(32), vertical: setWidth(60)),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(setWidth(22))),
            child: Column(
              children: [
                Center(
                  child: Text.rich(TextSpan(
                    text: '获取获奖机会',
                    style: TextStyle(
                        color: Color(0xff222222), fontSize: setWidth(34)),
                  )),
                ),
                SizedBox(
                  height: setWidth(20),
                ),
                _getItemWidget(
                    title: '还可以使用积分兑换$integral次',
                    actionText: '兑换',
                    actionEnable: integral > 0,
                    callback: () => actionEvent(0)),
                _getItemWidget(
                    title: '还可以分享获取$share次',
                    actionText: '分享',
                    actionEnable: share > 0,
                    callback: () => actionEvent(1)),
                _getItemWidget(
                    title: '还可以下单获取$purchase次',
                    actionText: '去下单',
                    actionEnable: purchase > 0,
                    callback: () => actionEvent(2)),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget _getItemWidget({
    String title,
    String actionText,
    VoidCallback callback,
    bool actionEnable,
  }) {
    return Container(
        margin: EdgeInsets.only(bottom: setWidth(40)),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style:
                  TextStyle(color: Color(0xff666666), fontSize: setWidth(30)),
            ),
            GestureDetector(
              onTap: () {
                if (actionEnable) {
                  callback();
                }
              },
              child: Container(
                height: setWidth(90),
                width: setWidth(160),
                alignment: Alignment.center,
                decoration: actionEnable
                    ? BoxDecoration(
                        gradient: LinearGradient(
                            begin: Alignment.topCenter,
                            end: Alignment.bottomCenter,
                            colors: [
                              Color(0xffffdb96),
                              Color(0xffffb342),
                            ]),
                        borderRadius: BorderRadius.circular(setWidth(45)))
                    : BoxDecoration(
                        color: Color(0xffcccccc),
                        borderRadius: BorderRadius.circular(setWidth(45))),
                child: Text(
                  actionText,
                  style: TextStyle(
                      color: Color.fromARGB(255, 245, 35, 63),
                      fontSize: setWidth(32)),
                ),
              ),
            )
          ],
        ));
  }
}
